home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / AniArea.java < prev    next >
Text File  |  1998-09-15  |  4KB  |  104 lines

  1. /*
  2.  * @(#)AniArea.java    1.10 98/03/18
  3.  *
  4.  * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  7.  * modify and redistribute this software in source and binary code form,
  8.  * provided that i) this copyright notice and license appear on all copies of
  9.  * the software; and ii) Licensee does not utilize the software in a manner
  10.  * which is disparaging to Sun.
  11.  *
  12.  * This software is provided "AS IS," without a warranty of any kind. ALL
  13.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  14.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  15.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  16.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  17.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  18.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  19.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  20.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  21.  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  22.  * POSSIBILITY OF SUCH DAMAGES.
  23.  *
  24.  * This software is not designed or intended for use in on-line control of
  25.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  26.  * the design, construction, operation or maintenance of any nuclear
  27.  * facility. Licensee represents and warrants that it will not use or
  28.  * redistribute the Software for such purposes. *
  29.  */
  30.  
  31. import java.awt.Graphics;
  32. import java.util.StringTokenizer;
  33. import java.awt.Image;
  34. import java.net.URL;
  35. import java.net.MalformedURLException;
  36.  
  37. /**
  38.  * This ImageArea provides for a button that animates when the mouse is
  39.  * over it. The animation is specifed as a base image that contains all
  40.  * of the animation frames and then a series of X,Y coordinate pairs that
  41.  * define the top left corner of each new frame.
  42.  *
  43.  * @author    Chuck McManis
  44.  * @version    1.10, 03/18/98
  45.  */
  46. class AniArea extends ImageMapArea {
  47.  
  48.     Image sourceImage;
  49.     int     nFrames;
  50.     int  coords[];
  51.     int     currentFrame = 0;
  52.  
  53.     public void handleArg(String s) {
  54.     StringTokenizer st = new StringTokenizer(s, ", ");
  55.     int    i;
  56.         String imgName;
  57.  
  58.     imgName = st.nextToken();
  59.     try {
  60.         sourceImage = parent.getImage(new URL(parent.getDocumentBase(),
  61.                           imgName));
  62.         parent.addImage(sourceImage);
  63.     } catch (MalformedURLException e) {}
  64.  
  65.     nFrames = 0;
  66.     coords = new int[40];
  67.  
  68.     while (st.hasMoreTokens()) {
  69.         coords[nFrames*2]     = Integer.parseInt(st.nextToken());
  70.         coords[(nFrames*2)+1] = Integer.parseInt(st.nextToken());
  71.         nFrames++;
  72.         if (nFrames > 19)
  73.         break;
  74.     }
  75.     }
  76.  
  77.     public boolean animate() {
  78.     if (entered) {
  79.         repaint();
  80.     }
  81.     return entered;
  82.     }
  83.  
  84.     public void enter() {
  85.     currentFrame = 0;
  86.     parent.startAnimation();
  87.     }
  88.  
  89.     public void highlight(Graphics g) {
  90.     if (entered) {
  91.         drawImage(g, sourceImage, 
  92.               X-coords[currentFrame*2], Y-coords[(currentFrame*2)+1],
  93.               X, Y, W, H);
  94.         currentFrame++;
  95.         if (currentFrame >= nFrames)
  96.         currentFrame = 0;
  97.     }
  98.     }
  99.   public String getAppletInfo() {
  100.     return "Title: AniArea \nAuthor: Chuck McManis \nThis ImageMapArea subclass provides for a button that animates when the mouse is over it. The animation is specifed as a base image that contains all of the animation frames and then a series of X,Y coordinate pairs that define the top left corner of each new frame.";
  101.   }
  102. }
  103.  
  104.